﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VK.Comm.TransactSql
{
    public static class WrapSql
    {
        public static string WrapTransaction(string tranName, string sql)
        {
            StringBuilder result = new StringBuilder();
            result.Append(" BEGIN TRANSACTION ").Append(tranName).Append(" ");
            result.Append(sql);
            result.Append(" IF @@ERROR=0 ");
            result.Append(" BEGIN ");
            result.Append(" COMMIT TRANSACTION ").Append(tranName);
            result.Append(" END ");
            result.Append(" ELSE ");
            result.Append(" BEGIN ");
            result.Append(" ROLLBACK TRANSACTION ").Append(tranName);
            result.Append(" END");
            return result.ToString();
        }
    }
}
